package cn.servlet;

import cn.dao.UserDao;
import cn.dao.UserDaoImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req,
                           HttpServletResponse resp)
            throws IOException {
        req.setCharacterEncoding("utf-8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        UserDao userDao = new UserDaoImpl();
        if (userDao.login(username, password) != null) {
            resp.sendRedirect("index.jsp");
        } else {
            resp.sendRedirect("fail.jsp");
        }
    }
}
